<?php

namespace app\admin\controller\mall;

use app\admin\traits\Curd;
use app\common\business\Wechat;
use app\common\controller\AdminController;
use app\common\model\MallAccountLog;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
/**
 * Class Account
 * @package app\admin\controller\system
 * @ControllerAnnotation(title="账户管理")
 */
class Account extends AdminController
{
    use Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new MallAccountLog();
    }
    /**
     * @NodeAnotation(title="账户列表")
     */
    public function index($id=''){
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParames();
            $where=[['mid','=',$id]];
            $count = $this->model
                ->where($where)
                ->count();
            $list = $this->model
                ->where($where)
                ->page($page, $limit)
                ->order('id ASC')
                ->select();
            foreach ($list as $k=>$v){
                $minfo =(new Wechat())->getOpenidById($v['openid']);
                $list[$k]['nickName'] =$minfo['nickName'];
            }
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        $this->assign('mbid',$id);
        return $this->fetch();
    }
}